package leetcode.tree;

import leetcode.tree.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mazouri
 * @create 2021-05-04 10:45
 */
public class _144_preorderTraversal {
    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        preorder(root,list);
        return list;
    }

    private void preorder(TreeNode root, List<Integer> list) {
        if (root == null){
            return;
        }

        list.add(root.val);
        preorder(root.left,list);
        preorder(root.right,list);
    }
}
